#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
inline void read(int &x){
	x=0;char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar(); 
}
int n,m,lt[N],a[N];
long long ans,f[N];
struct Tree{long long mx,tag;}t[N<<2];
inline void pushdown(int p){
	if(t[p].tag){
		t[2*p].mx+=t[p].tag;
		t[2*p+1].mx+=t[p].tag;
		t[2*p].tag+=t[p].tag;
		t[2*p+1].tag+=t[p].tag;
		t[p].tag=0;
	}
}
#define mid ((l+r)>>1)
void change(int p,int l,int r,int lt,int rt,long long y){
	if(lt<=l&&r<=rt){
		t[p].mx+=y,t[p].tag+=y;
		return;
	}
	pushdown(p);
	if(l<r){
		if(lt<=mid) change(2*p,l,mid,lt,rt,y);
		if(mid<rt) change(2*p+1,mid+1,r,lt,rt,y);
	}
	t[p].mx=max(t[2*p].mx,t[2*p+1].mx);
}
long long query(int p,int l,int r,int lt){
	if(lt<=l) return t[p].mx;
	pushdown(p);
	long long ans=query(2*p+1,mid+1,r,lt);
	if(lt<=mid) ans=max(query(2*p,l,mid,lt),ans);
	return ans; 
}
int main(){
	freopen("gonna.in","r",stdin);
	freopen("gonna.out","w",stdout);
	read(n);
	for(int i=1;i<=n;++i) read(a[i]),ans+=a[i];
	read(m);
	while(m--){
		int l,r;
		read(l),read(r);
		lt[r]=max(lt[r],l); 
	}
	int L=0;
	for(int i=1;i<=n;++i){
		f[i]=query(1,0,n,L);
		change(1,0,n,i,i,f[i]);
		change(1,0,n,0,i-1,a[i]);
		L=max(L,lt[i]);
	}
	printf("%lld\n",ans-query(1,0,n,L));
	return 0;
}

